<%@ page language="java" contentType="text/html; charset=US-ASCII"
    pageEncoding="US-ASCII"%>
<%@ page import="edu.uclm.esi.tysweb.ajedrez.utils.*" %>
<%@ page import="edu.uclm.esi.tysweb.ajedrez.dominio.*" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Ajedrez</title>
<%
	String boton=request.getParameter("boton");
	String email=request.getParameter("email");
	String pwd1=request.getParameter("pwd1");
	String pwd2=request.getParameter("pwd2");
	String msg=null;
	if (boton!=null) {
		if (pwd1==null || pwd2==null || pwd1.length()==0 || pwd2.length()==0) {
			msg="Las passwords deben coincidir";
		} else if (!pwd1.equals(pwd2)) {
			msg="Las passwords deben coincidir";
		} else if (email==null || email.length()==0) {
			msg="El email no puede estar vacío";
		} else if (email!=null && email.length()>45) {
			msg="El email no puede tener más de 45 caracteres";
		} else if (!ValidatorUtil.validateEmail(email)) {
			msg="La dirección de email es inválida";
		}
		if (msg==null) {
			try {
				Jugador.insert(email, pwd1);
				System.out.println("Insertado " + email);
			}
			catch (Exception e) {
				System.out.println(e.getMessage() + ": " + email);
			}
		}
	}
%>
</head>
<body>
	<form action="registrarSinAccion.jsp" method="post">
		<label>email:</label><input type="text" name="email" maxlength="45"/><br/>
		<label>Password:</label> <input type="password" name="pwd1"/><br/>
		<label>Repite password:</label> <input type="password" name="pwd2"/><br/>
		<input type="submit" name="boton" value="Aceptar"/>
	</form>
	<%= msg!=null ? "<font color=\"red\">" + msg + "</font>": "" %>
</body>
</html>